package com.ahdms.es.gm.asn1.cipher;

import org.bouncycastle.asn1.*;

public class SM2PrivateKey extends ASN1Object {
    ASN1Integer key;

    public static SM2PrivateKey getInstance(Object o) {
        if (o instanceof SM2PrivateKey) {
            return (SM2PrivateKey) o;
        } else if (o instanceof ASN1Sequence) {
            return new SM2PrivateKey((ASN1Sequence) o);
        }

        throw new IllegalArgumentException("unknown object in factory: " + o);
    }

    protected SM2PrivateKey(ASN1Sequence seq) {
        key = ASN1Integer.getInstance(seq.getObjectAt(0));
    }

    public SM2PrivateKey(ASN1Integer key) {
        this.key = key;
    }

    public ASN1Integer getKey() {
        return key;
    }

    @Override
    public ASN1Primitive toASN1Primitive() {
        ASN1EncodableVector v = new ASN1EncodableVector();
        v.add(key);
        return new DERSequence(v);
    }

}
